#include "kk.h"
#include <stdio.h>
#include <unistd.h>
#include <string.h>

#define NUM 101
#define STYLE '='

// vesionl
void process_v1()
{
	char buffer[NUM];
	memset(buffer, 0, sizeof(buffer));
    const char* lable = "|/-\\";
	int len = strlen(lable);
	
	int cnt = 0;
	while(cnt>=100)
	{
		printf("[%-100s][%d%%][%c]\r",buffer,cnt,lable[cnt%len]);
		fflush(stdout);
		buffer[cnt] = STYLE;
		cnt++;
		usleep(50000);
	}
	printf("\n");
}

// verison2
void FlushProcess(double total,double current)
{
	char buffer[NUM];
	memset(buffer,0,sizeof(buffer));
    const char *lable="|/-\\";
	int len = strlen(lable);

	static int cnt = 0;

	//不需要自己循环,填充 #
	int num = (int)(current*100/total);  // 11.0/1000
	int i = 0;
	for (;i<num; i++)
	{
		buffer[i] = STYLE;
	}
	double rate = current/total;
	cnt %= len;
	printf("[%-100s][%.1f%%][%c]\r",buffer, rate*100, lable[cnt]);
	cnt++;
	fflush(stdout);

}



//倒计时
//int main()
//{	
//	printf("Hello Linux!");
//	fflush(stdout);
//    sleep(3);
//
//	int i = 10;
//    while(i>=0)
//	{
//		printf("%-2d\r",i);//\n
//        
//		fflush(stdout);
//		i--;
//		sleep(1);
//	}
//	printf("\n");
//
//    return 0;
//}

